[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
fread() Read Unformatted Data from Stream
#include <stdio.h>
size_t fread(buffer,size,count,stream);
void *buffer; Storage location for data
size_t size; Item size in bytes
size_t count; Max number of items to read
FILE *stream; Pointer to file structure
fread() reads a maximum of 'count' items of data, each of length
'size' bytes, from the input 'stream' and stores them in 'buffer'.
If a file pointer is associated with 'stream', it is incremented by
the number of bytes actually read.
Returns: The number of items actually read. This number may
be less than 'count' if an error occurs or end-of-
file is reached before 'count'.
Notes: If 'stream' was opened in text mode, the replacement
of (CR-LF) with (LF) has no effect on the file
pointer return value.
-------------------------------- Example ---------------------------------
The following statements open an existing file, read 128 characters
from the file into a buffer, then print the contents of that buffer.
#include <stdio.h>
FILE *stream;
char buffer[128];
int x;
main()
{
if ((stream = fopen("book.dat","r+")) != NULL) {
fread(buffer, sizeof(char), 128, stream);
for (x = 0; x < 128; x++)
printf("%c",buffer[x]);
}
}
See Also:
fwrite()
read()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson